/*     */ package com.gserver.commons.core.async;
/*     */ 
/*     */ import java.util.concurrent.ExecutorService;

import com.gserver.commons.core.server.IMessageProcessor;
/*     */ 
/*     */ 
/*     */ public class AsyncOperation
/*     */ {
/*     */   private volatile int stage;
/*     */   private final ExecutorService asyncExecutor;
/*     */   private final IMessageProcessor messageProcessor;
/*     */   private final IIoOperation operation;
/*     */ 
/*     */   public AsyncOperation(IIoOperation operation, ExecutorService asyncExecutor, IMessageProcessor messageProcessor)
/*     */   {
/*  40 */     this.stage = 0;
/*  41 */     this.operation = operation;
/*  42 */     this.asyncExecutor = asyncExecutor;
/*  43 */     this.messageProcessor = messageProcessor;
/*     */   }
/*     */ 
/*     */   public void execute()
/*     */   {
/*  55 */     switch (this.stage)
/*     */     {
/*     */     case 0:
/*  59 */       this.stage = this.operation.doStart();
/*  60 */       if (this.stage == 1)
/*     */       {
/*  63 */         this.asyncExecutor.execute(new Runnable()
/*     */         {
/*     */           public void run()
/*     */           {
/*  69 */             AsyncOperation.this.execute();
/*     */           }
/*     */         });
/*     */       }
/*  73 */       else if (this.stage == 2)
/*     */       {
/*  75 */         this.stage = this.operation.doStop();
/*     */       }
/*  77 */       break;
/*     */     case 1:
/*  81 */       this.stage = this.operation.doIo();
/*  82 */       if (this.stage == 2)
/*     */       {
/*  85 */         ScheduleAsyncFinishMessage _msg = new ScheduleAsyncFinishMessage(System.currentTimeMillis(), this);
/*  86 */         this.messageProcessor.put(_msg);
/*     */       }
/*     */ 
/*  92 */       break;
/*     */     case 2:
/*  96 */       this.stage = this.operation.doStop();
/*     */     }
/*     */   }
/*     */ 
/*     */   public String toString()
/*     */   {
/* 105 */     String _operationName = this.operation != null ? this.operation.getClass().getName() : "null";
/* 106 */     return getClass() + " operation[" + _operationName + "]";
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\commons_core.jar
 * Qualified Name:     org.mmo.commons.core.async.AsyncOperation
 * JD-Core Version:    0.6.2
 */